package vip.youngboy.freejump.domain.bus;

import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

/**
 * 业务对象关联业务表关系对象
 */
@Data
public class BusTableRel {

    private String id;

    private String tableKey;

    private String commont;

    private String type;

    private List<BusTableRel> children;

    private List<BusTableFk> fks;

    private BusTable busTable;

    private BusObj busObj;


    public List<BusTableRel> listAllTableRel() {
        List<BusTableRel> rels = Lists.newArrayList();
        for (BusTableRel child : this.children) {
            //递归获取所有子关系
            rels.addAll(child.listAllTableRel());
        }
        return rels;
    }

    public BusTableRel find(String tableKey) {
        if (this.tableKey.equals(tableKey)) {
            return this;
        } else {
            //尝试到子类中查找
            if (this.children != null) {
                for (BusTableRel child : this.children) {
                    BusTableRel busTableRel = child.find(tableKey);
                    if (busTableRel != null) {
                        return busTableRel;
                    }
                }
            }
        }

        return null;
    }


}
